/* GUI CONVERTED from ppptrp6a.i (converter v1.75) Sun Aug 13 13:49:06 2000 */
/* ppptrp6a.i  INCLUDE FILE TO FIND THE STANDARD COST AS OF DATE        */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*V8:ConvertMode=FullGUIReport                                          */
/* REVISION: 7.3      LAST MODIFIED: 06/02/95   by: dzs *G0NZ*          */
/* REVISION: 7.3      LAST MODIFIED: 10/13/95   by: str *G0ZG*          */
/* REVISION: 9.0      LAST MODIFIED: 05/11/00   BY: *J3PB* Kirti Desai  */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00   BY: *N0KQ* myb          */


      /* FIND THE STANDARD COST AS OF DATE */


      /* FIND THE BEGINNING COST ON THE FIRST CST-ADJ XACTION
         AFTER THE SELECTED DATE. THIS COST - TR_PRICE
         SHOULD EQUAL THE COST AT END OF THE AS-OF DATE */

      /* HOWEVER, IF THIS IS THE FIRST TR_HIST RECORD,
         THEN ASSUME THAT THE COST AT THE END OF THE
         AS-OF DATE EQUALS THIS COST. */

/*G0ZG*   tr_recno = -1.                                                */

          /* FIND THE FIRST CST ADJ TRANSACTION AFTER THE AS OF DATE.  IF
         ONE IS AVAILABLE THEN GET THE DATE OF THIS CST ADJ TRANSACTION,
         AND THEN SORT THESE BY TRANSACTION NUMBER, WHICH ASSUMES THE
         TRANSACTION WITH THE LOWEST TRANSACTION NUMBER WAS DONE FIRST.
         THIS TRANSACTION SHOULD GIVE THE COST AT THE END OF THE AS
         OF DATE.  IF ACCEPT 0 COST IS YES, THEN COST WILL BE THE
         STD - PRICE.  IF ACCEPT 0 COST IS NO, THEN COST WILL BE THE
         STD.  IF NO CST ADJ TRANSACTION CAN BE FOUND AFTER THE AS
         OF DATE, THEN USE THE ITEM COST FROM THE SCT_DET RECORD */

/*J3PB**  find first tr_hist where tr_part = in_part             */


/*GUI global preprocessor directive settings */
&GLOBAL-DEFINE PP_PGM_RP TRUE
&GLOBAL-DEFINE PP_ENV_GUI TRUE


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

/*J3PB*/  for first tr_hist
/*J3PB*/     fields(tr_part tr_effdate tr_site tr_loc tr_ship_type
/*J3PB*/            tr_qty_loc tr_bdn_std tr_lbr_std tr_mtl_std tr_ovh_std
/*J3PB*/            tr_price tr_status tr_sub_std tr_trnbr tr_type)
/*J3PB*/     where tr_part    =  in_part
             and   tr_effdate >= as_of_date + 1
             and   tr_site    =  /*in_site*/ in_gl_cost_site
             and   tr_type    =  "CST-ADJ"
/*J3PB**     no-lock use-index tr_part_eff no-error.             */
/*J3PB*/     no-lock use-index tr_part_eff:
/*J3PB*/  end. /* FOR FIRST TR_HIST */

/*G0ZG*   if available tr_hist then tr_recno = recid(tr_hist).          */

/*G0ZG*   find first tr_hist where tr_part = in_part                    */
/*G0ZG*   and tr_site = in_site                                         */
/*G0ZG*   and tr_type = "CST-ADJ"                                       */
/*G0ZG*   and tr_effdate >= as_of_date + 1                              */
/*G0ZG*   no-lock use-index tr_part_eff no-error.                       */
    
          if available tr_hist then do:

         /* GET THE FIRST RECORD ENTERED EVEN IF TR_PART_EFF*/
         /* ISN'T IN TRANSACTION NUMBER SEQUENCE            */

             cst_date = tr_effdate.

/*J3PB**     for each tr_hist no-lock where tr_part = in_part           */

/*J3PB*/     for each tr_hist
/*J3PB*/        fields(tr_part tr_effdate tr_site tr_loc tr_ship_type
/*J3PB*/               tr_qty_loc tr_bdn_std tr_lbr_std tr_mtl_std tr_ovh_std
/*J3PB*/               tr_price tr_status tr_sub_std tr_trnbr tr_type)
/*J3PB*/        where tr_part    = in_part
                and   tr_effdate = cst_date
                and   tr_site    = /*in_site*/ in_gl_cost_site
                and   tr_type    = "CST-ADJ"
                use-index tr_part_eff
                by tr_trnbr.

                trrecno = recid(tr_hist).
               leave.
            end. /* FOR EACH TR_HIST */

/*J3PB**   find tr_hist no-lock where recid(tr_hist) = trrecno.         */

/*J3PB*/     /* BEGIN ADD SECTION */

             for first tr_hist
                fields(tr_part tr_effdate tr_site tr_loc tr_ship_type
                       tr_qty_loc tr_bdn_std tr_lbr_std tr_mtl_std tr_ovh_std
                       tr_price tr_status tr_sub_std tr_trnbr tr_type)
                where recid(tr_hist) = trrecno no-lock:
             end. /* FOR FIRST TR_HIST */

/*J3PB*/     /* END ADD SECTION */

             std_as_of = (tr_mtl_std + tr_lbr_std + tr_ovh_std
                          + tr_bdn_std + tr_sub_std).

/*fdn*/
             lbr_as_of = tr_lbr_std.
             sub_as_of = tr_sub_std.

/*G0ZG*       if tr_recno <> recid(tr_hist)                         */
/*G0ZG*       or (tr_recno = recid(tr_hist)                         */
/*G0ZG*       and tr_price <> std_as_of) then                       */

/*G0ZG*/      if tr_price <> std_as_of or zero_cost then
              std_as_of = std_as_of - tr_price.

           end.
           else do:
              {gpsct03.i &cost=sct_cst_tot}
              std_as_of = glxcst.

              /*fdn*/ {hkgpsct03.i}

           end.

    
           find first sct_det no-lock where sct_sim = "Current" and sct_part = in_part and sct_site = in_gl_cost_site no-error.
           if available sct_det then
               cur_as_of = sct_cst_tot.
		    	
		   cur_std = round(total_qty_oh * cur_as_of,2). 	
           ext_std = round(total_qty_oh * std_as_of,2).
           lbr_std = round(total_qty_oh * lbr_as_of,2).
           sub_std = round(total_qty_oh * sub_as_of,2).
